package org.jaaksi.test.jpush.ui;

import android.app.Activity;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.widget.Toast;
import org.jaaksi.test.jpush.JPushReceiver;
import org.jaaksi.test.jpush.MyApplication;
import org.jaaksi.test.jpush.util.ConstantUtils;
import org.jaaksi.test.jpush.util.EventBusTool;

/**
 * Created by Fcy on 2016/1/23. <br/>
 * 这是个tabActivity，有三个tab fragment 在Activity注册了三个action广播， fragment列表拉去数据时，
 * 读取sp判断对应是否存在未读消息，如果存在则发送广播给TabActivity接收，然后更新小红点
 * 也可以用EventBus取代这里的广播
 */
public class OtherActivity extends Activity
{
//	private BroadcastReceiver mReceiver = new BroadcastReceiver()
//	{
//		@Override
//		public void onReceive(Context context, Intent intent)
//		{
//			if (ConstantUtils.Action.ACTION_RECEIVER_PUSH_HOUSE_FEED_NEWHOUSE
//	                .equals(intent.getAction())
//	                || ConstantUtils.Action.ACTION_RECEIVER_PUSH_HOUSE_FEED_BUY
//	                        .equals(intent.getAction())
//                )
//			{
//				initPoint();
//			}
//		}
//	};

	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
        EventBusTool.register(this);

        // initPoint();
//		registerMsgFeedReceiver();
		// 清除通知栏的消息，不要再这里清除吧，可不可以设置点击通知的时候清除，从通知调过来的intent是什么，能不能判断
		((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
		        .cancel(JPushReceiver.REPLY_NOTIFY_ID);

	}

//	private void registerMsgFeedReceiver()
//	{
//		IntentFilter intentFilter = new IntentFilter();
//		intentFilter.addAction(
//		        ConstantUtils.Action.ACTION_RECEIVER_PUSH_HOUSE_FEED_NEWHOUSE);
//		intentFilter.addAction(
//		        ConstantUtils.Action.ACTION_RECEIVER_PUSH_HOUSE_FEED_BUY);
//		intentFilter.addAction(
//		        ConstantUtils.Action.ACTION_RECEIVER_PUSH_HOUSE_FEED_RENT);
//		LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver,
//		        intentFilter);
//	}

	/**
	 * 初始化小红点
	 */
	private void initPoint()
	{
		Toast.makeText(MyApplication.getInstance(), "ahaha", Toast.LENGTH_LONG)
		        .show();

	}

	@Override
	protected void onDestroy()
	{
//		LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
        EventBusTool.register(this);
		super.onDestroy();
	}
}